package com.example.chapter06;

import android.widget.FrameLayout;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import com.example.chapter06.fragment.DetailFragment;
import com.example.chapter06.fragment.ListFragment;

public class FragmentActivity extends AppCompatActivity {
    FragmentTransaction fragmentTransaction;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment);

        findViewById(R.id.fgly_list);
        findViewById(R.id.fgly_detail);


        // 法二：动态添加fragment
     DetailFragment detailFragment = new DetailFragment();
    ListFragment listFragment = new ListFragment();
    fragmentTransaction = getSupportFragmentManager().beginTransaction();
    fragmentTransaction.add(R.id.fgly_list,listFragment);
    fragmentTransaction.add(R.id.fgly_detail,detailFragment) ;
    fragmentTransaction.commit(); // 提交事务
    }

}